#include "mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
{
    xc=200; yc=100; r=50; col=0;
    /*lay.addWidget(&line);
    wid.setLayout(&lay);
    this->setCentralWidget(&wid);
    line.setText("Press");*/
}

MainWindow::~MainWindow()
{
}
void MainWindow::keyPressEvent(QKeyEvent *event)
{
    switch (event->key())
    {
    case Qt::Key_Up: if(yc-r>0) { yc--; update();}
        break;
    case Qt::Key_Down: if(yc+r<480) { yc++; update();}
        break;
    case Qt::Key_Left: if(xc-r>0) { xc--; update();}
        break;
    case Qt::Key_Right: if(xc+r<640) { xc++; update();}
        break;
    case Qt::Key_Equal: if(r<200) { r++; update();}
        break;
    case Qt::Key_Minus: if(r>10) { r--; update();}
        break;
    case Qt::Key_C:  col=(col+1)%6; update();
        break;
    }
}
void MainWindow::paintEvent(QPaintEvent *event)
{
    QPainter paint(this);
    paint.setRenderHint(QPainter::Antialiasing, true);
    switch (col)
    {
    case 0: paint.setBrush(QBrush(Qt::white));
        break;
    case 1: paint.setBrush(QBrush(Qt::red));
        break;
    case 2: paint.setBrush(QBrush(Qt::yellow));
        break;
    case 3: paint.setBrush(QBrush(Qt::green));
        break;
    case 4: paint.setBrush(QBrush(Qt::blue));
        break;
    case 5: paint.setBrush(QBrush(Qt::black));
    }
    krug(&paint, xc, yc, r);
}
void MainWindow::krug(QPainter *paint, int cx, int cy, int r)
{
    paint->drawEllipse(cx-r, cy-r, 2*r, 2*r);
}
void MainWindow::Draw(QPainter *paint)
{
    krug(paint, 200, 100, 100);
}
